package com.example.lt.entity.video;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Objects;

/**
 * @Author 小涛Tao
 * @Date: 2024/08/12/11:29
 * version 1.0 注释：视频热度信息封装类
 **/
@Data
@NoArgsConstructor
@ToString
public class HotVideo implements Serializable {

    private static final long serialVersionUID = 1L;

    String hotFormat; // 格式

    Double hot; // 热度

    Long videoId; // 视频id

    String title; // 视频标题

    public HotVideo(Double hot,Long videoId,String title){
        this.hot = hot;
        this.videoId = videoId;
        this.title = title;
    }

    public void hotFormat(){
        BigDecimal bigDecimal = new BigDecimal(this.hot);
        BigDecimal decimal = bigDecimal.divide(new BigDecimal("10000"));
        DecimalFormat formater = new DecimalFormat("0.0");
        formater.setRoundingMode(RoundingMode.HALF_UP);    // 5000008.89
        String formatNum = formater.format(decimal);
        this.setHotFormat( formatNum+"万");
    }

    // 重写equals方法，根据【视频id】和【视频标题】两个属性来比较两个对象是否相等
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        HotVideo hotVideo = (HotVideo) o;
        return Objects.equals(videoId, hotVideo.videoId) &&
                Objects.equals(title, hotVideo.title);
    }

    // 重写hashCode方法，只根据【videoId】和【title】这两个属性来生成哈希值
    @Override
    public int hashCode() {
        return Objects.hash(videoId, title);
    }

}
